log using "\\file\UsersW$\wrr15\Home\My Documents\My Files\META-ANALYSIS AND PUBLICATION BIAS\REVISION FOR RESEARCH SYNTHESIS METHODS\PROGRAMS\TABLE3top.smcl", replace
// This program takes about 2 hours to run on a standard laptop
etime, start
set matsize 10000
drop _all
clear
graph drop _all
set more off
set seed 52256
matrix RESULTS = J(4,6,0)
local studies = 100
local estperstudy = 10
local totalobs = `studies'*`estperstudy'
local alpha = 1
local theta = 1
local obs = 100

                simulate effectMED = r(effectMED) effectMIN = r(effectMIN) effectP5 = r(effectP5) ///
						 effectP95 = r(effectP95) effectMAX = r(effectMAX)  ///
						 teffectMED = r(teffectMED) teffectMIN = r(teffectMIN) teffectP5 = r(teffectP5) ///
						 teffectP95 = r(teffectP95) teffectMAX = r(teffectMAX)  ///	
						 N = r(N) I2 = r(I2) pctsig = r(pctsig) , ///
                         reps(1000): PANELsample, studies(`studies') estperstudy(`estperstudy') totalobs(`totalobs') alpha(`alpha') ///
						 theta(`theta') obs(`obs') 						 
						 
				summ effectMED, meanonly
                matrix RESULTS[1,1] = r(mean)
                summ effectMIN, meanonly
                matrix RESULTS[1,2] = r(mean)
                summ effectP5, meanonly
                matrix RESULTS[1,3] = r(mean)
                summ effectP95, meanonly
                matrix RESULTS[1,4] = r(mean)
                summ effectMAX, meanonly
                matrix RESULTS[1,5] = r(mean)
                summ N, meanonly
                matrix RESULTS[1,6] = r(mean)
				
				summ teffectMED, meanonly
                matrix RESULTS[2,1] = r(mean)
                summ teffectMIN, meanonly
                matrix RESULTS[2,2] = r(mean)
                summ teffectP5, meanonly
                matrix RESULTS[2,3] = r(mean)
                summ teffectP95, meanonly
                matrix RESULTS[2,4] = r(mean)
                summ teffectMAX, meanonly
                matrix RESULTS[2,5] = r(mean)
                summ N, meanonly
                matrix RESULTS[2,6] = r(mean)
								
				summ pctsig, detail
				matrix RESULTS[3,1] = r(mean)
				matrix RESULTS[3,2] = r(min)		
				matrix RESULTS[3,3] = r(p5)
				matrix RESULTS[3,4] = r(p95)
				matrix RESULTS[3,5] = r(max)
                summ N, meanonly
                matrix RESULTS[3,6] = r(mean)	
				
				summ I2, detail
				matrix RESULTS[4,1] = r(mean)
				matrix RESULTS[4,2] = r(min)		
				matrix RESULTS[4,3] = r(p5)
				matrix RESULTS[4,4] = r(p95)
				matrix RESULTS[4,5] = r(max)
                summ N, meanonly
                matrix RESULTS[4,6] = r(mean)	
				

matrix colnames RESULTS = MED MIN P5 P95 MAX N
matrix rownames RESULTS = EFFECT TEFFECT PCTSIG HETERO 
matrix list RESULTS

etime

log close
